<script setup lang="ts">
import { useRouter } from 'vue-router'
// 定义Props类型:
interface Props {
  title?: string
  rightText?: string
  onBack?: () => void
}
// 定义Emits类型:
interface Emits {
  (e: 'click-right'): void
}

const props = defineProps<Props>()
const emit = defineEmits<Emits>()

const router = useRouter()

// 2. 封装默认行为
const clickLeft = () => {
  if (props.onBack) return props.onBack()
  router.back()
}
</script>

<template>
  <van-nav-bar
    @click-right="emit('click-right')"
    left-arrow
    fixed
    placeholder
    :title="title"
    :right-text="rightText"
    @click-left="clickLeft"
  />
</template>

<style lang="scss" scoped>
::v-deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }

    &__text {
      font-size: 15px;
    }
  }
}
</style>
